package com.meilai.project.service.middleware.impl;

import com.meilai.project.service.middleware.KeyGenerateService;
import org.springframework.stereotype.Service;

/**
 * @author 张驰
 * @date 2020/9/29 10:49
 */
@Service
public class KeyGenerateServiceImpl implements KeyGenerateService {
//    @Autowired
//    RedisTemplate<String, String> redisTemplate;
//
//    /**
//     * SpringBoot获取当前环境代码,Spring获取当前环境代码
//     */
//    @Value("${spring.profiles.active}")
//    private String profiles;
//
//    @Override
//    public String getConsultSequence() {
//        //时间戳 后面拼接流水号
//        String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//        RedisAtomicLong counter_consult = new RedisAtomicLong("sequence_consult_"+datetime ,redisTemplate.getConnectionFactory());
//        long counter = counter_consult.incrementAndGet();
//        if (counter == 1) {// 初始设置过期时间
//            counter_consult.expire(1, TimeUnit.DAYS);// 单位天
//        }
//        return "HJZX"+datetime+ StringUtils.leftPad(String.valueOf(counter), 4, "0");
//    }
//
//    @Override
//    public String getOrderSetSequence() {
//        String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//        RedisAtomicLong counter_order_set = new RedisAtomicLong("sequence_order_set_"+datetime ,redisTemplate.getConnectionFactory());
//        long counter = counter_order_set.incrementAndGet();
//        if (counter == 1) {// 初始设置过期时间
//            counter_order_set.expire(1, TimeUnit.DAYS);// 单位天
//        }
//        return "2"+("prod".equals(profiles)?"0":"1")+datetime+ StringUtils.leftPad(String.valueOf(counter), 9, "0");
//    }
//
//    @Override
//    public String getRefundSequence() {
//        String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//        RedisAtomicLong counter_refund = new RedisAtomicLong("sequence_refund_"+datetime ,redisTemplate.getConnectionFactory());
//        long counter = counter_refund.incrementAndGet();
//        if (counter == 1) {// 初始设置过期时间
//            counter_refund.expire(1, TimeUnit.DAYS);// 单位天
//        }
//        return "3"+("prod".equals(profiles)?"0":"1")+datetime+ StringUtils.leftPad(String.valueOf(counter), 9, "0");
//    }
//
//    @Override
//    public String getH5PayIdSequence() {
//        String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());
//        RedisAtomicLong counter_h5_pay = new RedisAtomicLong("sequence_h5_pay_"+datetime ,redisTemplate.getConnectionFactory());
//        long counter = counter_h5_pay.incrementAndGet();
//        if (counter == 1) {// 初始设置过期时间
//            counter_h5_pay.expire(1, TimeUnit.DAYS);// 单位天
//        }
//        return "H5PAY"+"4"+("prod".equals(profiles)?"0":"1")+datetime+ StringUtils.leftPad(String.valueOf(counter), 9, "0");
//    }
}
